package org.meluk.billboard.beans.user;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.meluk.billboard.jpa.User;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope("singleton")
public class UserHolder {

    //online users
    private static final Set<User> users;

    static {
        users = Collections.synchronizedSet(new HashSet<User>());
    }

    public static void putUser(User user) {
        users.add(user);
    }

    public static boolean removeUser(User user) {
        return users.remove(user);
    }

    public static synchronized User[] getUsers() {
        return users.toArray(new User[users.size()]);
    }

    public static Boolean isOnline(User user) {
        return users.contains(user);
    }
}
